//SteadyMaple stuff
//www.steadymaple.com
//(C)Marat

package client;
import handling.channel.ChannelServer;
import java.rmi.RemoteException;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;


import server.MapleInventoryManipulator;
import server.TimerManager;
import tools.MaplePacketCreator;

import server.Randomizer;
import server.maps.MapleMap;
//End stupid imports




public class SteadyMaple {
public static int[] tv = {9201066, 9250023, 9250024, 9250025, 9250026, 9250042, 9250043, 9250044, 9250045, 9250046, 9270000, 9270001, 9270002, 9270003, 9270004, 9270005, 9270006, 9270007, 9270008, 9270009, 9270010, 9270011, 9270012, 9270013, 9270014, 9270015, 9270016, 9270040, 9270066};
//^ blocked NPCs


    //MapleClient instance start
    public static MapleClient c;

    public SteadyMaple(final MapleClient c) {
	this.c = c;
    }

    public final MapleClient getClient() {
	return c;
    }
    //MapleClient isntance end


    public static void main() {





  //Start connected loop
TimerManager.getInstance().register(new Runnable() {
public final void run() {
 StringBuilder conStr = new StringBuilder("Connected Clients: ");
  Map<Integer, Integer> connected = null;
                    try {
                        connected = ChannelServer.getInstance(1).getWorldInterface().getConnected();
                    } catch (RemoteException ex) {
                        Logger.getLogger(ChannelServer.class.getName()).log(Level.SEVERE, null, ex);
                    }
	    boolean first = true;
	    for (int i : connected.keySet()) {
		if (!first) {
		    conStr.append(", ");
		} else {
		    first = false;
		}
		if (i == 0) {
		    conStr.append("Total: ");
		    conStr.append(connected.get(i));
		} else {
		    conStr.append("Channel");
		    conStr.append(i);
		    conStr.append(": ");
		    conStr.append(connected.get(i));
		}
	    }
	    System.out.println(conStr.toString());
}
}, 30000);

//end connected loop

//START SteadyTip
TimerManager.getInstance().register(new Runnable() {
public final void run() {

    String[] messages = {
    "Please help support SteadyMaple one of 2 ways. 1)Click the SteadyMS Sponsored links on top of www.steadymaple.com every 30 minutes or 2) Donate and receive great and powerful rewards! Thanks in advanced!",
    "Use the @npc command to open the SteadyMS index NPC. This NPC can link you to all the importent NPCs in SteadyMaple.",
    "If you are under level 50, you can get GM buffs for free by going to @npc -> GM Buffs.",
    "You can gain 80 @cash randomly by killing monsters",
    "You can buy useful goods from the general shop. You can access the general shop through @npc",
    "You can trade maple leafs for maple items. Use @npc to access the maple leaf trader.",
    "When you are a level 200 adventurer or 120 cygnus, you can reset. Reseting will make you level 1, you keep your AP,SP, and job. So after you reset you can keep leveling and get stronger and stronger!",
    "If NPCs stop working for some reason, use the @dispose command and try again. They will most likley start working again.",
    };
    int totalmessages = messages.length;
    int crandom = Randomizer.nextInt(totalmessages);

for (ChannelServer cserv : ChannelServer.getAllInstances()) {
cserv.broadcastPacket(MaplePacketCreator.serverNotice(6, "[SteadyTip]"+messages[crandom]));
}

}
}, 60000);
//END SteadyTip

//Start FM clear
TimerManager.getInstance().register(new Runnable() {
public final void run() {

MapleMap map;
for (int i = 1; i <= 22; i++) {
for (ChannelServer cserv : ChannelServer.getAllInstances()) {
map = cserv.getMapFactory(5).getMap(910000000 + i);
if (map.getAllPlayer().size() <= 0) {
map.killAllMonsters(false);
}
}
}
for (ChannelServer cserv : ChannelServer.getAllInstances()) {
cserv.broadcastPacket(MaplePacketCreator.serverNotice(6, "::FREE MARKET ROOMS CLEANED::"));

}

}
}, 600000);
//End FM clear

//Start dragon egg
TimerManager.getInstance().register(new Runnable() {
public void run() {



int mapid = 24004611;
int mapid2 = 24004612;
int eggid = 4001094; // Nine Spirit Egg
int neweggid = 2041200; //Dragon Stone
short gain = 1;
short loose = -1;

for (ChannelServer cserv : ChannelServer.getAllInstances()) {
    for (int w = 5; w <= 6; w++){
  for (MapleCharacter player : cserv.getMapFactory(w).getMap(mapid).getCharacters()) {
    if (player.haveItem(eggid, 1, false, true)){
        MapleInventoryManipulator.removeById(player.getClient(), MapleInventoryType.ETC, eggid, loose, true, true);
        MapleInventoryManipulator.addById(player.getClient(), neweggid, gain);
       
    }

    }


    }
    }
}
}, 60000);

//End dragon egg

        

    }

}




